﻿/************************************************************************
 * SMLib - State Model Library
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     SMLib\Utils\Hashing\HashAlgos_Horner.cs
 * Description  :     Horner Rule for hashing a block of integers
 * Change log   :     -Jan 2012:  First version
 * To Do        :     
 ************************************************************************/
using System;

namespace SMLib.Utils.Hashing
{

    /// <summary>
    /// Horner Rule for hashing a block of integers
    /// </summary>
    public class HashAlgos_Horner
    {
        /// <summary>
        /// This method is proposed by [state space generation technique in mobius framework]
        /// Using Horner Rule for hashing a block of integers!
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public static int HashByHornerRule(int[] a)
        {
            //Check the function!
            int Horner = a[0];
            for (int i = 1; i < a.Length; i++)
            {
                Horner = ((Horner * 32 + a[i]) % int.MaxValue);
            }
            return Horner;
        }
    }
}
